package com.example.fw;

import com.example.tests.Contact;

public class ContactHelper extends HelpersBase{


        public ContactHelper(ApplicationManager applicationManager) {
        		super(applicationManager);
        }

        public void createContact(Contact contact){
                initContactCreation();
                fillContactForm(contact);
                confirmContactCreation();
        }

        public void deleteContact(Contact contact){
            initContactCreation();
            fillContactForm(contact);
            confirmContactCreation();
    }
        
        private void initContactCreation(){
                manager.getAutoItHelper()
                                .winWaitAndActivate("AddressBook Portable", "", 5000)
                                .click("Add");
        }

        private void fillContactForm(Contact contact){
        	    manager.getAutoItHelper()
                                .winWaitAndActivate("Add Contact", "", 5000)
                                .send("TDBEdit12", contact.getFirstname())
                                .send("TDBEdit11", contact.getLastname());
        }

        private void confirmContactCreation() {
        	     manager.getAutoItHelper()
                                .click("Save")
                                .winWaitAndActivate("AddressBook Portable", "", 5000);
        }

		public Contact getFirstContact() {
			manager.getAutoItHelper().focus("TListView1")
			.send("{DOWN}{SPACE}")
			.click("Edit")
			.winWaitAndActivate("Update Contact", "", 5000);
		Contact contact = new Contact()
		.setFirstname(manager.getAutoItHelper().getText("TDBEdit12"))
		.setLastname(manager.getAutoItHelper().getText("TDBEdit11"));
		manager.getAutoItHelper().click("Cancel")
		.winWaitAndActivate("Update Contact", "", 5000);
		return contact;
			
		}

}